<template>
  <asset-fixed @update="update"></asset-fixed>

  <view style="padding: 30rpx 24rpx">
    <view style="font-size: 24rpx; color: #adadad; margin-bottom: 30rpx">共{{ total }}条记录</view>
    <view v-for="(item, idx) in list" :key="idx" style="margin-bottom: 25rpx">
      <asset-item :info="item"></asset-item>
    </view>
    <view style="font-size: 24rpx; color: #adadad; text-align: center; margin: 110rpx 0">
      — 已显示全部资产 —
    </view>
  </view>
  <image-modal ref="imageRef" @download="onDownload"></image-modal>
</template>

<script setup>
  import { adStore } from '@/biz/ad'
  import { messageStore } from '@/biz/message'

  import assetItem from '@/com/asset-item.vue'
  import imageModal from '@/com/image-modal.vue'
  import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
  import { ref } from 'vue'
  import mgr from './biz'
  import assetFixed from './com/asset-fixed.vue'

  const [imageRef] = [ref()]
  const [total, list] = [ref(), ref([])]

  onLoad(() => {
    adStore()
      .show()
      .then((res) => {
        if (res) imageRef.value.show({ image: res })
      })
    messageStore().show()
  })

  function onDownload() {
    adStore().count()
  }

  onPullDownRefresh(() => {
    update()
  })

  let tmp = {}
  function update(info) {
    if (info) tmp = info
    mgr.assetList(tmp).then(
      (res) => {
        total.value = res.total
        list.value = res.list
        uni.stopPullDownRefresh()
      },
      () => {
        uni.stopPullDownRefresh()
      }
    )
  }
</script>
<style lang="scss" scoped></style>
